import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pizza_test/model/chefmodel.dart';

import 'chef_finish_status.dart';

class FootActionView extends StatelessWidget {
  
  final List<Chef> chefs;
  final Function addPizzaAction;
  final Function closeAllAction;

  const FootActionView({Key key, this.chefs, this.addPizzaAction, this.closeAllAction}) : super(key: key);
  
  Widget _createContainer([Widget child]) {

    final bordersize = BorderSide(
            width: 1,
            color: Colors.grey
          );
    return Container(
      decoration: BoxDecoration(
        border: Border(
          left: bordersize,
          bottom: bordersize,
        )
      ),
      child: child,
    );
  }

  Widget _createAddButton(String number, VoidCallback callback) {
    return Container(
      alignment: Alignment.center,
      child: Column(
        children: <Widget>[
          GestureDetector(
            onTap: callback,
            child: Container(
              decoration: BoxDecoration(
                color: Colors.blueAccent,
                border: Border.all(width: 1, color: Colors.black),
                borderRadius: BorderRadius.all(Radius.circular(10))
              ),
              margin: const EdgeInsets.only(top: 30, bottom: 10),
              padding: const EdgeInsets.all(10),
              child: Text("Add $number pizza", style: TextStyle(color: Colors.white),)
            ),
          ),
          Text("add $number pizza")
        ],
      )
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
            child: Row(
              children: <Widget>[
                Flexible(
                  flex: 3,
                  child: FootPizzaCurrentNum(chefs: chefs,),
                ),
                Flexible(
                  flex: 1,
                  child: _createContainer(
                    Container(
                      alignment: Alignment.topRight,
                      padding: const EdgeInsets.all(5),
                      child: Text("Action Buttons:"),
                    ),
                  ),
                ),
                Flexible(
                  flex: 1,
                  child: _createContainer(
                    _createAddButton("10", (){
                      this.addPizzaAction(10);
                    })
                  )
                ),
                Flexible(
                  flex: 1,
                  child: _createContainer(
                    _createAddButton("100",(){
                      this.addPizzaAction(100);
                    })
                  ),
                ),
                Flexible(
                  flex: 1,
                  child: ManagerAllChefView(closeAllAction: closeAllAction),
                ),
              ],
            ),
          );
  }
}

// 开启关闭所有厨师
class ManagerAllChefView extends StatefulWidget {

  final Function closeAllAction;

  const ManagerAllChefView({Key key, this.closeAllAction}) : super(key: key);


  @override
  _ManagerAllChefViewState createState() => _ManagerAllChefViewState();
}

class _ManagerAllChefViewState extends State<ManagerAllChefView> {

  var begin = false;
  @override
  Widget build(BuildContext context) {
    final bordersize = BorderSide(
            width: 1,
            color: Colors.grey
          );
    return Container(
      decoration: BoxDecoration(
        border: Border(
          left: bordersize,
          bottom: bordersize,
          right: bordersize
        )
      ),
      child: Container(
                  alignment: Alignment.topCenter,
                  padding: const EdgeInsets.all(5),
                  child: Column(
                    children: <Widget>[
                      Text(
                        "Factory main switch,waring,this will turn off all chefs",
                      ),
                      CupertinoSwitch(
                        value: begin,
                        onChanged: (val){
                          setState(() {
                            begin = !begin;
                            if(widget.closeAllAction != null) widget.closeAllAction(begin);
                          });
                        },
                      )
                    ],
                  ),
                ),
    );
  }
}